package com.ruoyi.yuan.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yuan.domain.Cell;
import com.ruoyi.yuan.service.ICellService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 网格Controller
 * 
 * @author guifeng
 * @date 2022-08-21
 */
@Api("网格管理")
@RestController
@RequestMapping("/yuan/cell")
public class CellController extends BaseController
{
    @Autowired
    private ICellService cellService;

    /**
     * 查询网格列表
     */
    @ApiOperation("查询网格列表")
    @PreAuthorize("@ss.hasPermi('yuan:cell:list')")
    @GetMapping("/list")
    public AjaxResult list(Cell cell)
    {
        List<Cell> list = cellService.selectCellList(cell);
        return AjaxResult.success(list);
    }

    /**
     * 导出网格列表
     */
    @ApiOperation("导出网格列表")
    @PreAuthorize("@ss.hasPermi('yuan:cell:export')")
    @Log(title = "网格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cell cell)
    {
        List<Cell> list = cellService.selectCellList(cell);
        ExcelUtil<Cell> util = new ExcelUtil<Cell>(Cell.class);
        util.exportExcel(response, list, "网格数据");
    }

    /**
     * 获取网格详细信息
     */
    @ApiOperation("获取网格详细信息")
    @PreAuthorize("@ss.hasPermi('yuan:cell:query')")
    @GetMapping(value = "/{cellId}")
    public AjaxResult getInfo(@PathVariable("cellId") Long cellId)
    {
        return AjaxResult.success(cellService.selectCellByCellId(cellId));
    }

    /**
     * 新增网格
     */
    @ApiOperation("新增网格")
    @PreAuthorize("@ss.hasPermi('yuan:cell:add')")
    @Log(title = "网格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cell cell)
    {
        cell.setCreateBy(getUsername());
        return toAjax(cellService.insertCell(cell));
    }

    /**
     * 修改网格
     */
    @ApiOperation("修改网格")
    @PreAuthorize("@ss.hasPermi('yuan:cell:edit')")
    @Log(title = "网格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cell cell)
    {
        return toAjax(cellService.updateCell(cell));
    }

    /**
     * 删除网格
     */
    @ApiOperation("删除网格")
    @PreAuthorize("@ss.hasPermi('yuan:cell:remove')")
    @Log(title = "网格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cellIds}")
    public AjaxResult remove(@PathVariable Long[] cellIds)
    {
        return toAjax(cellService.deleteCellByCellIds(cellIds));
    }
}
